Skip to content

feat(velocity): make discovery config env-var driven#36

Merged
lusu007 merged 1 commit intomainfrom
feat/velocity-env-config
Apr 26, 2026
Merged

feat(velocity): make discovery config env-var driven#36
lusu007 merged 1 commit intomainfrom
feat/velocity-env-config

Conversation

@hbrombeer
Copy link
Copy Markdown
Member

@hbrombeer hbrombeer commented Apr 26, 2026

Summary

Replaces the hardcoded companion object constants in DiscoveryService with a DiscoveryConfig data class loaded from environment variables. All keys are optional; defaults match the previous hardcoded behaviour, so existing prod deployments are unaffected (no chart change required).

New env vars (all optional)

Env var Default Purpose
GROUNDS_AGONES_NAMESPACE games (falls back to POD_NAMESPACE first) Where to list GameServers
GROUNDS_AGONES_LABEL_SELECTOR grounds/server-type in (lobby,game,match) Empty = no k8s-side filter
GROUNDS_AGONES_LOBBY_LABEL grounds/server-type Empty = treat every running GS as lobby
GROUNDS_AGONES_LOBBY_VALUE lobby Value of lobbyLabel that marks a lobby
GROUNDS_AGONES_RUNNING_STATES Ready,Allocated,Reserved CSV
GROUNDS_AGONES_POLL_INTERVAL 2s Accepts Ns / Nm / Nh
GROUNDS_AGONES_ADDRESS_TYPE PodIP PodIP / ExternalIP / InternalIP / Hostname
GROUNDS_AGONES_PORT 25565

Why

Even ignoring any specific context, configurable beats hardcoded for a plugin like this:

  • Multi-context reuse — the same JAR runs in prod (`games` namespace, server-type filter), per-dev clusters (own namespace, no role filtering), and a shared staging cluster, instead of forking the plugin per context.
  • No code change for ops tweaks — adjusting poll interval, adding a new server-type, or pointing at `ExternalIP` becomes a chart-values update; no plugin release required.
  • Cleaner code — magic constants disappear, the config surface is documented in one data class, easier to review and test.
  • K8s-idiomatic — env vars + Downward API + `ConfigMap envFrom` is the 12-factor / K8s shape; no file mounts, no hot-reload logic, secrets via `secretKeyRef` work directly.
  • Future-proof for routing modes — when staging needs hostname-based routing, the existing config knob pattern absorbs it cleanly (one more env var, one more code path), instead of a parallel plugin.

The plugin entrypoint logs the resolved config on startup so operators can see what's loaded.

Test plan

  • 14 unit tests in `DiscoveryConfigTest` — defaults, override precedence, empty/whitespace handling, malformed values, per-dev cluster preset
  • `./gradlew :velocity:build` green locally
  • Behaviour identical when no env vars are set (prod regression check via the "empty env yields prod-compatible defaults" test)

Adds JUnit 5 `testImplementation` to the velocity module (no tests existed before).

Replaces the hardcoded `companion object` constants in DiscoveryService
with a `DiscoveryConfig` data class loaded from environment variables.
All keys are optional and the defaults match the previous hardcoded
behaviour, so existing prod deployments are unaffected.

New env vars (all optional):
- GROUNDS_AGONES_NAMESPACE (falls back to POD_NAMESPACE Downward API,
  then "games")
- GROUNDS_AGONES_LABEL_SELECTOR (empty string = no k8s-side filter)
- GROUNDS_AGONES_LOBBY_LABEL (empty string = treat every running GS as
  lobby — useful in per-dev / staging clusters)
- GROUNDS_AGONES_LOBBY_VALUE
- GROUNDS_AGONES_RUNNING_STATES (CSV)
- GROUNDS_AGONES_POLL_INTERVAL (2s / 5m / 1h)
- GROUNDS_AGONES_ADDRESS_TYPE (PodIP / ExternalIP / …)
- GROUNDS_AGONES_PORT

Motivation: the same plugin needs to run in three contexts — prod
(games namespace, server-type filter), per-dev vClusters (Phase 3.1a in
grounds-platform: own namespace, no role filtering), and the shared
staging cluster (Phase 3.2). Cloud-native config via env vars +
ConfigMap envFrom + Downward API is the Kubernetes-idiomatic shape and
avoids forking the plugin per context.

Plugin entrypoint logs the resolved config on startup so operators can
see what is actually loaded.

14 unit tests in DiscoveryConfigTest cover defaults, override
precedence, empty/whitespace-handling, malformed values, and the
per-dev cluster preset. Adds JUnit 5 testImplementation to the velocity
module (no tests existed before).
@sonarqubecloud
Copy link
Copy Markdown

@hbrombeer hbrombeer requested a review from lusu007 April 26, 2026 10:46
@lusu007 lusu007 merged commit 4735f8c into main Apr 26, 2026
3 checks passed
@lusu007 lusu007 deleted the feat/velocity-env-config branch April 26, 2026 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants